"""
requests类库的helloWorld: requests类库是依赖urllib3类库实现的
"""
import json

import requests
import simplejson

base_url = 'http://httpbin.org/get'

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'


with requests.request('GET', base_url, headers={'User-agent': user_agent}) as response:
    # requests.models.Response
    print(type(response))
    # response: Response = Response()
    print(response.status_code, response.reason)
    # 展示二进制内容, 可通过修改base_url为www.bing.com查看content和text的不同内容
    print(response.content)
    # simplejson与Python内建的json组件
    print(simplejson.loads(response.content))
    print(type(simplejson.loads(response.content)))
    # simplejson.dumps(obj)将Python类型转为json
    print("*" * 100)
    print(json.loads(response.content))
    print(type(json.loads(response.content)))
    print(response.headers)
    # 展示转换后的文本内容
    print(response.text)
    print(response.request)
